const express = require("express");
const app = express();

var bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({ extended: false }));

const path = require('path');
app.use(express.static(path.join(__dirname, 'public')));

/**
 * 设置跨域
 */

app.all("*",function(req,res,next){
    //设置允许跨域的域名，*代表允许任意域名跨域
    res.header("Access-Control-Allow-Origin","*");
    //允许的header类型
    res.header("Access-Control-Allow-Headers","content-type");
    //跨域允许的请求方式
    res.header("Access-Control-Allow-Methods","DELETE,PUT,POST,GET,OPTIONS");
    if (req.method.toLowerCase() == 'options')
        res.send(200);  //让options尝试请求快速结束
    else
        next();
})

/**
 * 引入路由
 */
const axios = require("./axios/axios.js");
const file = require("./file/upload.js");
const http = require("./http/index.js");


app.get("/",(req,res)=>{
    res.json({
        ifSuccess:true,
        data:{
            msg:"测试用例"
        }
    })
});

app.use("/axios",axios)
app.use("/file",file)
app.use("/http",http)

app.listen("9000",()=>{
    console.log('\x1B[33m%s\x1b[0m\x1B[36m%s\x1B[0m', "本机服务启动与：","http://localhost:9000");
})